package com.corner.utils.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * Created by Administrator on 2015/5/8.
 */
public class RoundedImageView extends ImageView {
    private Bitmap roundBitmap;

    public RoundedImageView(Context context) {
        super(context);
        init();
    }

    public RoundedImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public RoundedImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public Bitmap getRoundBitmap() {
        return roundBitmap;
    }

    private void init() {
    }

    @Override
    public void setImageBitmap(Bitmap bm) {
        if (this.roundBitmap != null) {
            this.roundBitmap.recycle();
            this.roundBitmap = null;
            System.gc();
        }
//        if (bm != null) {
//            this.bm = bm;
//            int width_height = bm.getWidth() > bm.getHeight() ? bm.getHeight() : bm.getWidth();
//            src = new Rect(0, 0, width_height, width_height);
//            des = new Rect(0, 0, getMeasuredHeight(), getMeasuredHeight());
//            if (roundBitmap == null) {
//                roundBitmap = BitmapUtil.getRoundedBitmap(bm, src, des, getMeasuredWidth() / 8, getMeasuredHeight() / 8);
//            }
//        }
        super.setImageBitmap(bm);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }
}
